<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LaborTeam extends Model
{
    use HasFactory;

    protected $appends = [
        'sex_text'
    ];

    protected $fillable = [
        'labor_company_id',
        'admin_id',
        'role_id',
        'company_id',
        'name',
        'number',
        'director',
        'id_card',
        'sex',
        'type',
        'is_cooperate',
        'work_type_num',
        'daily_wage',
        'contact_mobile',
        'id_card_files',
        'birthday',
        'address',
        'recommended',
        'is_contract',
        'files',
        'remarks',
        'scene',
        'scene_mobile',
        'scene_id_card',
        'in_time',
        'out_time',
        'in_flexible_minutes',
        'out_flexible_minutes',
        'late_threshold',
        'early_leave_threshold',
    ];
    const POSTONLY = [
        'labor_company_id',
        'admin_id',
        'role_id',
        'company_id',
        'name',
        'number',
        'director',
        'id_card',
        'sex',
        'type',
        'is_cooperate',
        'work_type_num',
        'daily_wage',
        'contact_mobile',
        'id_card_files',
        'birthday',
        'address',
        'recommended',
        'is_contract',
        'files',
        'remarks',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getSexTextAttribute()
    {
        return $this->sex == 1 ? '男' : '女';
    }

    public function resources()
    {
        return $this->hasMany(ResourceBind::class,'source_id','id')->where('model','LaborTeam')->with('resource');
    }

}
